package com.czh.intelligentoj.model.vo;


import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.czh.intelligentoj.judge.codesandbox.model.JudgeInfo;
import com.czh.intelligentoj.model.entity.QuestionSubmit;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import java.util.Date;

/*
 * ClassName: Question
 * Package: com.czh.intelligentoj.model.entity
 * Description:
 *             对数据脱敏操作
 * @Author: CZH
 * @Create: 2024
 */
@Data
public class QuestionSubmitVO {
    /**
     * id
     */
    private Long id;

    /**
     * 题目编程语言
     */
    private String proLanguage;

    /**
     * 题目
     */
//    @TableField("title_code")
    private String titleCode;
    /**
     *
     */
    private JudgeInfo judgeInfo;
    /**
     * 提交状态
     */
//    @TableField("title_status")
    private Integer titleStatus;
    /**
     * 题目id
     */
//    @TableField("question_id")
    private Long questionId;
    /**
     * 提交用户的id
     */
    @TableField("user_id")
    private Long userId;
    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;
    /**
     * 提交用户信息
     */
//    private UserVO user;
    /**
     * 题目信息
     */
//    private QuestionVO question;

    private static final long serialVersionUID = 1L;


    /**
     * 包装类转对象
     *
     * @param questionSubmitVO
     * @return
     *       JSON字符串
     */
    public static QuestionSubmit voToObj(QuestionSubmitVO questionSubmitVO) {
        if (questionSubmitVO == null) {
            return null;
        }
        QuestionSubmit questionSubmit = new QuestionSubmit();
        BeanUtils.copyProperties(questionSubmitVO, questionSubmit);
        JudgeInfo judgeInfo = questionSubmitVO.getJudgeInfo();
        if (judgeInfo != null) {
            questionSubmit.setJudgeInfo(JSONUtil.toJsonStr(judgeInfo));
        }
        return questionSubmit;
    }

    /**
     * 对象转包装类
     *
     * @param questionSubmit
     * @return
     *       questionVO对象
     */
    public static QuestionSubmitVO objToVo(QuestionSubmit questionSubmit) {
        if (questionSubmit == null) {
            return null;
        }
        QuestionSubmitVO questionSubmitVO = new QuestionSubmitVO();
        BeanUtils.copyProperties(questionSubmit, questionSubmitVO);
        String judgeInfoStr = questionSubmit.getJudgeInfo();
        questionSubmitVO.setJudgeInfo(JSONUtil.toBean(judgeInfoStr, JudgeInfo.class));
        return questionSubmitVO;
    }
}
